package pub.cleangao.common.util;

import java.security.SecureRandom;
import java.util.Random;


public class RandomStr {

    private static final Random random = new SecureRandom();

    /**
     * 获取数字随机数
     */
    public static String digits(int length) {
        String str = "0123456789";
        int len = 10;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            int number = random.nextInt(len);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }


    /**
     * 混合大小写字母与数字
     */
    public static String mixed(int length) {
        String str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        int len = 62;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            int number = random.nextInt(len);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

    /**
     * 随机字母字符串
     */
    public static String character(int length) {
        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        int len = 52;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; ++i) {
            int number = random.nextInt(len);
            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

}
